require(['config'], () => {
  require(['jquery', 'swiper', 'artTemplate', 'include'], ($, Swiper, template) => {
    class IndexPage {
      constructor() {
        this.initSwiper()
        this.loadHotProducts()
        this.loadAllProducts()
      }

      initSwiper () {
        // $.getJSON('http://www.xiongmaoyouxuan.com/api/tab/1?start=0', data => console.log('成功', data))
        $.ajax({
          url: 'http://www.xiongmaoyouxuan.com/api/tab/1?start=0',
          method: 'GET',
          headers: {
            "x-platform": "pc"
          },
          data: {
            start: 0
          },
          dataType: 'json',
          success: resData => {
            const { data } = resData
            const html = template('slide-template', { slides: data.banners })
            $('.swiper-wrapper').html(html)
          },
          error: err => {
          },
          complete: data => {
          }
        })
        new Swiper('.swiper-container', {
          // 循环模式选项
          loop: true,
          //自动循环
          autoplay: true,
          // 如果需要分页器
          pagination: {
            el: '.swiper-pagination',
          },
          // 如果需要前进后退按钮
          navigation: {
            nextEl: '.swiper-button-next',
            prevEl: '.swiper-button-prev',
          },
          // 如果需要滚动条
          scrollbar: {
            el: '.swiper-scrollbar',
          },
        })
      }

      loadHotProducts () {
        $.ajax({
          url: 'http://www.xiongmaoyouxuan.com/api/tab/1?start=0',
          headers: {
            "x-platform": "pc"
          },
          data: {
            start: 0
          },
          dataType: 'json',
          success (resData) {
            const html = template('hot-template', { products: resData.data.items.list })
            $('.fendin > ul').html(html)
          }

        })
      }
      loadAllProducts () {
        $.ajax({
          url: 'http://www.xiongmaoyouxuan.com/api/tab/1?start=0',
          dataType: 'json',
          success (resData) {
          }
        })

      }

    }
    new IndexPage()
  })
})